package com.example.shopping_mall.base;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.example.shopping_mall.MainActivity;
import com.example.shopping_mall.R;
import com.example.shopping_mall.adapter.BrandDetailAdapter;
import com.example.shopping_mall.bean.BrandBean;
import com.example.shopping_mall.bean.BrandMiddleBean;
import com.example.shopping_mall.bean.SkuLastBean;
import com.example.shopping_mall.http.ShoppingRequest;
import com.example.shopping_mall.utils.ShoppingUtils;

import java.util.ArrayList;
import java.util.List;

//品牌详情
public class RecommendDetailActivity extends AppCompatActivity {

    private static final String TAG = RecommendDetailActivity.class.getSimpleName();

    private ShoppingRequest shoppingRequest;
    RecyclerView detail_recyclerView;
    List<BrandBean> brandBeanList;
    ImageView image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_detail);

        shoppingRequest=new ShoppingUtils();
        init();
    }

    private void init() {
        Intent intent=getIntent();
        int brand_id=intent.getExtras().getInt("brand_id");
        Log.d(TAG, "init: "+brand_id);

        detail_recyclerView=findViewById(R.id.recommend_detail_recyclerView);
        detail_recyclerView.setLayoutManager(new LinearLayoutManager(this));
        brandBeanList=new ArrayList<>();

        shoppingRequest.requestHomeBrandAppMore(brand_id, new ShoppingUtils.OnfindSmsHomeBrandAppListener() {
            @Override
            public void OnfindSmsHomeBrandAppRequest(BrandMiddleBean[] beans) {
                    BrandBean brandBean= beans[brand_id].getPmsBrand();

                    //UiBrandDetail recommendDetail=new UiBrandDetail();
                    brandBean.setName(beans[brand_id].getPmsBrand().getName());
                    Log.d(TAG, "init: "+beans[brand_id].getPmsBrand().getName());
                    brandBean.setBigPic(beans[brand_id].getPmsBrand().getBigPic());
                    Log.d(TAG, "init: "+beans[brand_id].getPmsBrand().getBigPic());
                    brandBean.setBrandStory(beans[brand_id].getPmsBrand().getBrandStory());
                    Log.d(TAG, "init: "+beans[brand_id].getPmsBrand().getBrandStory());

                brandBeanList.add(brandBean);
                BrandDetailAdapter detailAdapter=new BrandDetailAdapter(RecommendDetailActivity.this,brandBeanList);
                detail_recyclerView.setAdapter(detailAdapter);
            }
        });

        shoppingRequest.requestProductAttribute(new ShoppingUtils.OnPmsProductAttributeRequestListener() {
            @Override
            public void OnProductAttributeRequest(SkuLastBean[] lastBeans) {
                for (int i = 0; i < lastBeans.length; i++) {
                    String stu[]=lastBeans[i].getInputList().split(",");
                    for (String s:stu) {
                        Log.d(TAG, "Attribute: "+s);
                    }
                }
            }
        });

        //返回主页面
        image=findViewById(R.id.recommend_detail_back);
        image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(RecommendDetailActivity.this, MainActivity.class));
            }
        });
    }
}